

function ActionManager(shapeManager, canvasManager)
{	
	this.data = [];
	
	this.data_backup = [];
	
	this.flushDataBackup = function(){
	
		this.data_backup = [];
	}
	
	
	this.addAction = function(action)
	{
		this.data.push(action);
		//console.log("Adding data -> " + this.data.length);
	}
	
	
	this.undo = function()
	{
		// Used for redo
		
		if (this.data.length > 0){
			
			//console.log("It's here 1 -> " + this.data[this.data.length - 1].action );
			this.data_backup.push(this.data[this.data.length - 1]);
			
			switch (this.data[this.data.length - 1].action)
			{
				////console.log("It's here 2");
				case DRAW_ACTION:
					shapeManager.undo();
					//console.log("It's here 3");
					break;
				case MOVE_ACTION:
					
					// Reaffect original coordinates
					shapeManager.getData()[this.data[this.data.length - 1].id].setRealX(this.data[this.data.length - 1].previousRealX);
					shapeManager.getData()[this.data[this.data.length - 1].id].setRealY(this.data[this.data.length - 1].previousRealY);
					break;
			}
			
			this.data.pop();
			
			canvasManager.drawOptimisedCanvas(shapeManager.getData(), canvasManager.getBackCanvas(), null);
		}
	}
	
	
	this.redo = function()
	{
		if (this.data_backup.length > 0){
		
			this.data.push(this.data_backup[this.data_backup.length - 1]);
			
			switch (this.data_backup[this.data_backup.length - 1].action)
			{
				case DRAW_ACTION:
					shapeManager.redo();
					break;
				case MOVE_ACTION:
					
					// Reaffect changed coords
					shapeManager.getData()[this.data[this.data.length - 1].id].setRealX(this.data[this.data.length - 1].nextRealX);
					shapeManager.getData()[this.data[this.data.length - 1].id].setRealY(this.data[this.data.length - 1].nextRealY);
					break;
			}
			
			this.data_backup.pop();
			
			canvasManager.drawOptimisedCanvas(shapeManager.getData(), canvasManager.getBackCanvas(), null);
		}
	}
}